package be.myandroid.games;

import javax.microedition.khronos.opengles.GL10;

public class MovingCircle extends Circle{
	
	private static float MAX[] = Configuration.getInstance().MAX_SCREEN_SIZE;
	private float xSpeed = 0.02f;
	private float ySpeed = 0.02f;
	
	public MovingCircle(float xPos, float yPos, float zPos) {
		super(xPos, yPos, zPos);
		setRandomSpeed();
	}
	
	private void setRandomSpeed() {
		xSpeed = (float) (0.01f * (Math.random() - 0.5));
		ySpeed = (float) (0.01f * (Math.random() - 0.5));
	}

	public MovingCircle(){
		super(0f, 0f, 0f);
		pos[X] = MAX[X] * (2f * (float)Math.random() - 1f);
		pos[Y] = MAX[Y] * (2f * (float)Math.random() - 1f);
		setRandomSpeed();
	}
	
	public void move(int duration){
		pos[X] += xSpeed * duration;
		pos[Y] += ySpeed * duration;
		
		if(pos[X] > MAX[X] || pos[X] < -MAX[X])
			xSpeed = -xSpeed;
		if(pos[Y] > MAX[Y] || pos[Y] < -MAX[Y])
			ySpeed = -ySpeed;
	}
	
	public double getDistance(float[] pushPos) {
		double xDist = Math.abs(this.pos[Circle.X]- pushPos[Circle.X] * MAX[X]);
		double yDist = Math.abs(this.pos[Circle.Y] - pushPos[Circle.Y] * MAX[Y]);
		return xDist + yDist;
	}
	
	@Override
	public void draw(GL10 gl) {
		super.draw(gl);
	}
}
